package com.yungu.swift.schedule.utils;

import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationContext;

/**
 * @author : cuixiuyin
 * @date : 2019/8/14
 */
@Slf4j
public class QuartzContextUtils {


    public static ApplicationContext getApplicationContext(final JobExecutionContext jobExecutionContext) {
        try {
            return (ApplicationContext) jobExecutionContext.getScheduler().getContext().get("applicationContextKey");
        } catch (SchedulerException e) {
            log.error("jobExecutionContext.getScheduler().getContext() error!", e);
            throw new RuntimeException(e);
        }
    }
}
